Skip to content

Conversation

@ShenghaiWang
Copy link
Contributor

Closes #70

Make the "environment" parameter to @JavaMethod initializers optionally-typed and default to nil

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, seems that's what @DougGregor had in mind -- leaving to him to approve the javakit bits.

Module wise I'm not sure if the separate VM module gained us anything, either seems fine.

return [
"""
self = \(raw: tryKeyword) Self.dynamicJavaNewObject(in: environment\(raw: arguments))
let _environment = environment == nil ? \(raw: tryKeyword) JavaVirtualMachine.shared().environment() : environment!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this would be nicer, without resorting to the !

Suggested change
let _environment = environment == nil ? \(raw: tryKeyword) JavaVirtualMachine.shared().environment() : environment!
let environment =
if let environment {
environment
} else {
\(raw: tryKeyword) JavaVirtualMachine.shared().environment()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I had the same comment earlier ;)

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to remove the unnecessary force-unwraps, but otherwise this looks good to me and thank you!

public init(_ enumValue: \(raw: name), environment: JNIEnvironment) {
let classObj = try! JavaClass<Self>(in: environment)
public init(_ enumValue: \(raw: name), environment: JNIEnvironment? = nil) {
let _environment = environment == nil ? try! JavaVirtualMachine.shared().environment() : environment!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do this without the force-unwraps, even if it's more verbose:

let _environment = if let environment {
  environment
} else {
  try! JavaVirtualMachine.shared().environment()
}

return [
"""
self = \(raw: tryKeyword) Self.dynamicJavaNewObject(in: environment\(raw: arguments))
let _environment = environment == nil ? \(raw: tryKeyword) JavaVirtualMachine.shared().environment() : environment!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I had the same comment earlier ;)

@DougGregor
Copy link
Member

Module wise I'm not sure if the separate VM module gained us anything, either seems fine.

The VM module really didn't seem to be buying us anything, so I'm fine with collapsing it into JavaKit.

@ktoso ktoso merged commit 63ced64 into swiftlang:main Oct 23, 2024
11 checks passed
@ktoso
Copy link
Collaborator

ktoso commented Oct 23, 2024

LGTM, thanks a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the "environment" parameter to @JavaMethod initializers optionally-typed and default to nil

4 participants